package club.haomoon.boss.service.impl;

import club.haomoon.boss.service.IDecoratePageService;
import club.haomoon.boss.validate.article.DecoratePageValidate;
import club.haomoon.boss.vo.article.DecoratePageVo;
import club.haomoon.core.entity.article.DecoratePageData;
import club.haomoon.core.mapper.article.DecoratePageDataMapper;
import club.haomoon.core.util.DateUtil;
import com.baomidou.mybatisplus.core.toolkit.Assert;

import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;

/**
 * -------------------------
 * @Description:  页面装修实现服务类
 * @Author: Wangjianwei
 * @Date: 2025/02/18 17:29
 * -------------------------
 */
@Service
public class DecoratePageServiceImpl implements IDecoratePageService {

    @Resource
    DecoratePageDataMapper decoratePageDataMapper;

    /**
     * 页面装修详情
     * @param id 主键
     * @return DecoratePageVo
     */
    @Override
    public DecoratePageVo detail(Integer id) {
        DecoratePageData decoratePage = decoratePageDataMapper.selectById(id);
        Assert.notNull(decoratePage, "数据不存在!");
        DecoratePageVo vo = new DecoratePageVo();
        vo.setId(decoratePage.getId());
        vo.setName(decoratePage.getName());
        vo.setType(decoratePage.getType());
        vo.setData(decoratePage.getData());
        vo.setMeta(decoratePage.getMeta());

        vo.setCreateTime(DateUtil.timestampToDate(decoratePage.getCreateTime()));
        vo.setUpdateTime(DateUtil.timestampToDate(decoratePage.getUpdateTime()));
        return vo;
    }

    /**
     * 页面装修保存
     * @param decoratePageValidate 参数
     */
    @Override
    public void save(DecoratePageValidate decoratePageValidate) {
        DecoratePageData decoratePage = decoratePageDataMapper.selectById(decoratePageValidate.getId());
        Assert.notNull(decoratePage, "数据不存在!");

        decoratePage.setName(decoratePageValidate.getName());
        decoratePage.setType(decoratePageValidate.getType());
        decoratePage.setMeta(decoratePageValidate.getMeta());
        decoratePage.setData(decoratePageValidate.getData());
        decoratePage.setUpdateTime(System.currentTimeMillis() / 1000);
        decoratePageDataMapper.updateById(decoratePage);
    }

}
